﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace KOPLibrary.DataManagement.Cacheflow
{
    public static class DataLayer
    {
        public static string FlatFilePath
        {
            get
            {
                return Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\KOP\NakitAkis.xml";
            }
        }

        public static global::KOPLibrary.Cacheflow.CacheflowDs LoadCachflowData()
        {
            global::KOPLibrary.Cacheflow.CacheflowDs ds = new KOPLibrary.Cacheflow.CacheflowDs();
            if (File.Exists(FlatFilePath))
                ds.ReadXml(FlatFilePath);
            return ds;
            
        }

        internal static void SaveCachflowData(global::KOPLibrary.Cacheflow.CacheflowDs ds)
        {
            try
            {
                if (!Directory.Exists(Path.GetDirectoryName(FlatFilePath)))
                    Directory.CreateDirectory(Path.GetDirectoryName(FlatFilePath));
                ds.AcceptChanges();
                ds.WriteXml(FlatFilePath);
            }
            catch (Exception exc)
            {
                Util.ShowException(exc);
            }
        }
    }
}
